package com.ubing.boot.notesforjava.scheduled;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import io.lettuce.core.ScriptOutputType;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.net.SocketTimeoutException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

//@Component
public class MyScheduledTask extends Thread{


    private  Integer integer;
    @Scheduled(cron = "0 0 0 * * ?") // 每天零点执行
    @PostConstruct
    public void myTask() {
        // 定时执行的逻辑代码
        System.out.println("定时任务执行时间：" + new Date());
    }

    @PreDestroy
    public void cleanup() {
        // 执行任务结束时的逻辑代码
    }

    public void i(Integer i){
        System.out.println(i);
    };
    @Override
    public void run() {
        i(integer);
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
        threadLocal.set(1);
        System.out.println(threadLocal.get());
        new Thread(()->{
            threadLocal.set(2);
            System.out.println(threadLocal.get());
        }).start();
        TimeUnit.SECONDS.sleep(2);
        System.out.println(threadLocal.get());


    }
    private static LocalDateTime dateTimeStamp2LocalDate(Long timestamp) {
        return timestamp == null ? null : Instant.ofEpochMilli(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
    }
}
